package com.cmc.cloud.cmclink.doc.service.impl.special;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cmc.cloud.cmclink.doc.constants.errorconstant.SpecialCargoApplyErrorCodeConstants;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoApplyDO;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoCntrDO;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoOdoDO;
import com.cmc.cloud.cmclink.doc.entity.SpecialCargoVoyageDO;
import com.cmc.cloud.cmclink.doc.mapper.SpecialCargoOdoMapper;
import com.cmc.cloud.cmclink.doc.service.special.SpecialCargoValidateService;
import com.cmes.framework.common.exception.util.ServiceExceptionUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Odo类型货物校验器
 * @author: 申天青
 * @date: 2025/8/4
 */
@Service
public class OdoCargoValidateServiceImpl implements SpecialCargoValidateService {

    @Resource
    private SpecialCargoOdoMapper specialCargoOdoMapper;
    @Override
    public void validate(Long applyId, SpecialCargoApplyDO applyDO, List<SpecialCargoCntrDO> cntrDOList, List<SpecialCargoVoyageDO> specialCargoVoyageDos) {
        cntrDOList.forEach(cntr -> {
            SpecialCargoOdoDO odoDO = specialCargoOdoMapper.selectOne(new LambdaQueryWrapper<SpecialCargoOdoDO>().eq(SpecialCargoOdoDO::getCntrId, cntr.getId()));
            if (null == odoDO) {
                throw ServiceExceptionUtil.exception(SpecialCargoApplyErrorCodeConstants.SPECIAL_NO_ODO_ERROR);
            }
        });

    }

}
